package me.fenglu.deployserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class DeployServer 
{
	private static int clientNum = 0;
	
	public static String rootPath = "";
	
	static{
		rootPath = DeployServer.class.getClassLoader().getResource("").getPath();
		rootPath = rootPath.substring(0, rootPath.length() - "target/classes/".length()) + "code/";
	}
	
	
    public static void main( String[] args ) {
    	ServerSocket server = null;
    	try {
    		boolean flag = true;
			server = new ServerSocket(10240);
			while(flag) {
				Socket client = server.accept();
				Thread t = new Thread(new DeployHandler(client, clientNum++));
				t.start();
				while(t.isAlive()) {
				}
				client.close();
				System.err.println("");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(null != server) {
				try {
					server.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
    }
}
